preserveValueImports + isolatedModules -> type-only ambient const enums#47817
preserveValueImports + isolatedModules -> type-only ambient const enums#47817jablko wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
|
Possibly related to #46556 and #46626? @jablko can you open an issue for discussion of this PR too? My initial reaction is that, in the PR you mentioned, the maintainers of |
|
@sandersn My rationale is:
I've opened #48040 for this. It's related to #46626 in that deconstified enums (whether via that PR or a build step) are independent of this PR, but that's not as important as the other deconstification reasons (JS consumers, single-file transpilation, compile-time vs. runtime version compatibility). This PR deals with ambient const enums when |
|
To help with PR housekeeping, I'm going to close this PR while it's still waiting on its bug to be accepted. |
Currently, if you compile
import Big, { RoundingMode } from "big.js"withpreserveValueImportsandisolatedModulesthe import name is preserved and you get at runtime:import Big, { RoundingMode } from "big.js"; ^^^^^^^^^^^^ SyntaxError: Named export 'RoundingMode' not found. The requested module 'big.js' is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using: import pkg from 'big.js'; const { RoundingMode } = pkg;RoundingModeis an ambient const enum, defined in @types/big.js. There's no corresponding runtime value in big.js.This PR extends the existing
preserveValueImports+isolatedModulesrequirement, that imported types must be marked type-only, to ambient const enums.If you add the type modifier (
import Big, { type RoundingMode } from "big.js"), the compiler does remove the import name, solving the runtime error.This PR specifically excludes non-ambient const enums, because they don't lead to runtime errors. (The import name is preserved, but the const enum is also preserved, so not an error at runtime.)